<!--
 * @Author: hq
 * @Date: 2022-05-24 10:21:11
 * @LastEditors: hq
 * @LastEditTime: 2022-08-09 11:20:53
 * @Description: 编辑弹窗
 * @version: 1.0
-->
<template>
  <div class="dialog">
    <div class="content">
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="上级节点">
          <el-input
            v-model="ruleForm.tree_text"
            placeholder="请输入上级节点"
          ></el-input>
        </el-form-item>
        <el-form-item label="节点名称" prop="title">
          <el-input
            v-model="ruleForm.title"
            placeholder="请输入节点名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="节点图标" prop="icon">
          <el-input
            v-model="ruleForm.icon"
            placeholder="请输入节点图标"
          ></el-input>
        </el-form-item>
        <el-form-item label="方法" prop="action">
          <el-input
            v-model="ruleForm.action"
            placeholder="请输入路径"
          ></el-input>
        </el-form-item>
        <el-form-item label="路由" prop="router_addr">
          <el-input
            v-model="ruleForm.router_addr"
            placeholder="请输入路由"
          ></el-input>
        </el-form-item>

        <el-form-item label="排序" prop="sort">
          <el-input
            type="number"
            v-model="ruleForm.sort"
            placeholder="请输入排序"
          ></el-input>
        </el-form-item>
        <el-form-item label="所属模块" prop="model_type">
          <el-select v-model="ruleForm.model_type" placeholder="请选择">
            <el-option
              v-for="item in modelArr"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="位置" prop="position">
          <el-select v-model="ruleForm.position" placeholder="请选择">
            <el-option
              v-for="item in positionArr"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="状态" :required="true">
          <el-switch
            active-text="禁用"
            inactive-text="启用"
            :active-value="1"
            :inactive-value="0"
            class="tablescope"
            v-model="ruleForm.status"
          >
          </el-switch>
        </el-form-item>
        <el-form-item label="是否显示" :required="true">
          <el-switch
            active-text="隐藏"
            inactive-text="显示"
            :active-value="1"
            :inactive-value="0"
            class="tablescope"
            v-model="ruleForm.hide"
          >
          </el-switch>
        </el-form-item>
        <el-form-item label="是否公共使用" :required="true">
          <el-switch
            active-text="否"
            inactive-text="是"
            :active-value="1"
            :inactive-value="0"
            class="tablescope"
            v-model="ruleForm.pub"
          >
          </el-switch>
        </el-form-item>
      </el-form>
    </div>

    <div class="btn">
      <el-button type="primary" @click="handleSubmit">确 定</el-button>
    </div>
  </div>
</template>

<script>
import { doMenu } from "@/api/manager";
export default {
  props: ["rowData"],
  data() {
    return {
      current: "",
      treeData: [{ id: 0, title: "顶级节点" }],
      treeList: [],
      defaultProps: {
        /** 唯一标识 **/
        value: "id",
        /** 标签显示 **/
        label: "title",
        /** 子级 **/
        children: "children",
      },
      //这个是el-select要绑定的数据，等下需要赋值
      select_id: "",
      select_title: "",
      ruleForm: {
        tree_id: "",
        title: "",
        icon: "",
        action: "",
        router_addr: "",
        sort: "",
        model_type: 1,
        position: "list",
        status: 1,
        hide: 1,
        pub: 1,
      },
      modelArr: [
        {
          id: 1,
          name: "系统",
        },
      ],
      positionArr: [
        {
          id: "list",
          name: "list",
        },
        {
          id: "top",
          name: "top",
        },
        {
          id: "right",
          name: "right",
        },
      ],
      rules: {
        title: [{ required: true, message: "请输入节点名称", trigger: "blur" }],
      },
    };
  },
  methods: {
    //操作
    async doMenu(action_type) {
      const { msg, err } = await doMenu({
        // id: this.rowData.id,
        pid: this.rowData.id,
        module: this.ruleForm.model_type,
        title: this.ruleForm.title,
        icon: this.ruleForm.icon,
        action: this.ruleForm.action,
        route: this.ruleForm.router_addr,
        sort: this.ruleForm.sort,
        position: this.ruleForm.model_type,
        status: this.ruleForm.status,
        hide: this.ruleForm.hide,
        pub: this.ruleForm.pub,
        action_type: action_type,
      });
      if (err === 0) {
        this.$message({
          showClose: true,
          message: "操作成功！",
          type: "success",
        });
        this.$emit("handleClose");
      } else {
        this.$message({
          showClose: true,
          message: msg,
          type: "error",
        });
      }
    },
    handleSubmit() {
      //新增
      this.doMenu("ADD");
    },
  },
  created() {
    this.ruleForm.tree_id = this.rowData.pid;
    this.ruleForm.tree_text = this.rowData.title;
    console.log(this.rowData);
  },
};
</script>

<style lang="scss" scoped>
.dialog {
  padding: 0 20px;
  box-sizing: border-box;
  height: 100%;
  .content {
    height: 92%;
    overflow: auto;
    &::-webkit-scrollbar {
      width: 0;
    }
  }
  .row {
    display: flex;
    margin-bottom: 20px;
    .col {
      width: 100px;
      display: flex;
      align-items: center;
      justify-content: flex-end;
      flex-shrink: 0;
      margin-right: 10px;
    }
    .red {
      margin-right: 5px;
    }
  }
  .row:nth-child(3) {
    align-items: flex-start;
  }
  .el-input__inner {
    height: 36px;
    line-height: 36px;
  }
  //   .btn {
  //     box-sizing: border-box;
  //     .el-button {
  //       width: 100%;
  //     }
  //   }
}
/deep/.el-tree--highlight-current
  .el-tree-node.is-current
  > .el-tree-node__content {
  .el-tree-node__label {
    color: #2978ff !important;
  }
}
</style>
